import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zyj
 * @date 2022年06月10日 10:19
 */
public class Demo {
    public static void main(String[] args) {
        ReentrantLock reentrantLock = new ReentrantLock();
        new Thread("A") {
            @Override
            public void run() {
                reentrantLock.lock();
                for (int i = 0; i < 10; i++) {

                    System.out.println(Thread.currentThread().getName());
                    try {
                        sleep(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                reentrantLock.unlock();
            }
        }.start();
        new Thread("B") {
            @Override
            public void run() {
                reentrantLock.lock();
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName());
                    try {
                        sleep(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                reentrantLock.unlock();
            }
        }.start();


        new Thread("C") {
            @Override
            public void run() {
                try {
                    reentrantLock.lock();
                    for (int i = 0; i < 10; i++) {
                        System.out.println(Thread.currentThread().getName());

                        sleep(50);

                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    reentrantLock.unlock();
                }
            }
        }.start();


    }
}
